<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>张静的在线简历</title>
</head>
<body>
<div id="mainPdf" style="text-align: center">

</div>


<script src="./js/build/pdf.js"></script>

<script id="script">
    //
    // If absolute URL from the remote server is provided, configure the CORS
    // header on that server.
    //
    var url = './src/ZhangJing.pdf';
    var pdfPages = 2;
    //
    // The workerSrc property shall be specified.
    //
    pdfjsLib.GlobalWorkerOptions.workerSrc =
        './js/build/pdf.worker.js';

    //
    // Asynchronous download PDF
    //
    var loadingTask = pdfjsLib.getDocument(url);
    loadingTask.promise.then(function(pdf) {
        //
        // Fetch the first page
        //
        for (var i = 1; i<=pdf.numPages; i++) {
            renderPdf(pdf, i);
        }

    });
    function renderPdf(pdf,pageNum) {
        pdf.getPage(pageNum).then(function(page) {
            var scale = 1.5;
            var viewport = page.getViewport({ scale: scale, });

            //
            // Prepare canvas using PDF page dimensions
            //
            var mainCanvas = document.getElementById('mainPdf');
            var canvas = document.createElement('canvas');
            var context = canvas.getContext('2d');
            canvas.height = viewport.height;
            canvas.width = viewport.width;

            //
            // Render PDF page into canvas context
            //
            mainCanvas.appendChild(canvas);
            var renderContext = {
                canvasContext: context,
                viewport: viewport,
            };
            page.render(renderContext);
        });
    }
</script>
</body>
</html>